<?php
include "../config/koneksi.php";
//include "../config/library.php";
//include "../config/fungsi_indotgl.php";
//include "../config/fungsi_combobox.php";
include "../config/class_paging.php";

$act=$_GET['act'];
if($act=='hapus'){
	//echo "woi : ";
	mysql_query("DELETE FROM nilai WHERE nis='$_GET[nis]'");
	echo "<meta content='0;media.php?module=nilai' http-equiv='refresh' /> ";
}
	
if(isset($_POST['submit']))
{
	if($act=='input'){		
	/*
	echo "cik! <br>";
	echo "$_POST[nis] <br>"; 
	echo	"$_POST[kd_kelas] <br>";
	echo	"$_POST[nip] <br>"; 
	echo	"$_POST[kd_matpel] <br>";
	echo	"$_POST[ul] <br>"; 
	echo	"$_POST[uts] <br>"; 
	echo	"$_POST[uas] <br>"; 
	echo	"$_POST[nilai_akhir] <br>"; 
	echo	"$_POST[idx] <br>";
	*/
		$query = mysql_query("insert into nilai (
		nis, kd_kelas, nip, kd_matpel, ul,uts,uas,nilai_akhir, idx) values 
		('$_POST[nis]', 
		'$_POST[kd_kelas]', 
		'$_POST[nip]',
		'$_POST[kd_matpel]',
		'$_POST[ul]',
		'$_POST[uts]',
		'$_POST[uas]',
		'$_POST[nilai_akhir]',
		'$_POST[idx]') ");
		echo "<meta content='0;media.php?module=nilai' http-equiv='refresh' /> ";
	}	
	if($act=='edit'){
		//echo "nis : " . $_POST[nis] . "<br>";
		
		mysql_query("UPDATE nilai SET ul       = '$_POST[ul]',
										uas       = '$_POST[uas]',
										nilai_akhir       = '$_POST[nilai_akhir]',
										idx       = '$_POST[idx]'
                             WHERE nis   = '$_POST[nis]' AND
							 kd_kelas = '$_POST[kd_kelas]' AND
							 kd_matpel = '$_POST[kd_matpel]' 
							 ");
		
		//echo "nis : " . $_POST[nama] . "<br>";
		echo "<meta content='0;media.php?module=nilai' http-equiv='refresh' /> ";
	}	
}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>SMK Pasundan Rancaekek</title>

<link href="../css/templatemo_style.css" rel="stylesheet" type="text/css" />

<link rel="stylesheet" type="text/css" href="../css/ddsmoothmenu.css" />
<script type="text/javascript" src="../scripts/jquery.min.js"></script>
<script type="text/javascript" src="../scripts/ddsmoothmenu.js">

</script>

<script type="text/javascript">

ddsmoothmenu.init({
	mainmenuid: "templatemo_menu", //menu DIV id
	orientation: 'h', //Horizontal or vertical menu: Set to "h" or "v"
	classname: 'ddsmoothmenu', //class added to menu's outer DIV
	//customtheme: ["#1c5a80", "#18374a"],
	contentsource: "markup" //"markup" or ["container_id", "path_to_menu_file"]
})
 
</script>

<script type="text/javascript">
function hitungAdd() {
	 var ul = parseFloat(document.add.ul.value);	 
	 var uts = parseFloat(document.add.uts.value);
	 var uas = parseFloat(document.add.uas.value);
	 
	 var totUl = ul * 0.3;
	 var totUts = uts * 0.3;
	 var totUas = uas * 0.4;
	 var totAll = totUl + totUts + totUas ;
	 	 
	 var na = totAll.toFixed(2);
	 document.add.nilai_akhir.value = na;
	 
	 var idx = '';
	 if(na >8.5) { // > 8.5 
		idx = 'A';
	 }else if(na >= 8){ //8-8.5
		idx = 'B';
	 }else if(na > 6){ //7-7.59
		idx = 'C';
	 }else if(na >= 5){ //5-6
		idx = 'D';
	 }else{
		idx = 'E';
	 }
	 document.add.idx.value = idx;
 }
 
 function hitungEdit() {
	 var ul = parseFloat(document.edit.ul.value);	 
	 var uts = parseFloat(document.edit.uts.value);
	 var uas = parseFloat(document.edit.uas.value);
	 
	 var totUl = ul * 0.3;
	 var totUts = uts * 0.3;
	 var totUas = uas * 0.4;
	 var totAll = totUl + totUts + totUas ;
	 	 
	 var na = totAll.toFixed(2);
	 document.edit.nilai_akhir.value = na;
	 
	 var idx = '';
	 if(na >8.5) { // > 8.5 
		idx = 'A';
	 }else if(na >= 8){ //8-8.5
		idx = 'B';
	 }else if(na > 6){ //7-7.59
		idx = 'C';
	 }else if(na >= 5){ //5-6
		idx = 'D';
	 }else{
		idx = 'E';
	 }
	 document.edit.idx.value = idx;
 }
</script>
</head>

<body id="subpage">

<div id="templatemo_outer_sub_wrapper">
	<div id="templatemo_sub_wrapper">
    
    	<div id="templatemo_header_admin">		
            <?php
			include "menu_admin.php";
			?>
            <div class="cleaner"></div>

        </div> <!-- end of templatemo header -->
        
        <div id="templatemo_main">
        
          	<div class="col_w960 col_w960_last">
				<div class="col_w300 float_r">
                
                    <h3>Tentang Sekolah</h3>
                    <?php 
					include "menu_kiri.php";
					?>
                
                </div>  
                <div class="col_w600 float_l">
                    
                    <h2>Data Nilai Siswa</h2>
        		<input type=button value='Data Nilai Siswa' onclick="window.location.href='?module=nilai'">
        		<input type=button value='Tambah Nilai Siswa' onclick="window.location.href='?module=nilai&act=tambahnilai'">
				
        		<div id="contact_form">
				<?php
				switch($_GET[act]){
				default:
					echo "
          <form method=get action='$_SERVER[PHP_SELF]'>
          <input type=hidden name=module value=nilai>
          <div id=paging>Masukkan NIS : <input type=text name='nis'> <input type=submit value=Cari></div>
          </form>";

    if (empty($_GET['nis'])){
    echo "<table class='ijo' width='700'>  
          <tr id='ijo'><th>No</th><th>NIS</th> <th>Nama</th><th>Kelas</th>  <th>Mata Pelajaran</th> <th>Ulangan</th><th>UTS</th><th>UAS</th><th>NA</th><th>Indeks</th><th></th></tr>";

    $p      = new Paging;
    $batas  = 15;
    $posisi = $p->cariPosisi($batas);

    $tampil = mysql_query("SELECT k.kelas, n.*, s.nama, m.nama_matpel from nilai n, siswa s, kelas k, matpel m WHERE n.nis=s.nis AND n.kd_matpel=m.kd_matpel AND n.kd_kelas=k.kd_kelas ORDER BY kd_kelas ASC LIMIT $posisi,$batas");
    
  
    $no = $posisi+1;
    while($r=mysql_fetch_array($tampil)){      
      echo "<tr><td>$no</td>
                <td>$r[nis]</td>                
                <td>$r[nama]</td>                
                <td>$r[kelas]</td>
                <td>$r[nama_matpel]</td>
                <td>$r[ul]</td>
                <td>$r[uts]</td>
                <td>$r[uas]</td>
                <td>$r[nilai_akhir]</td>
                <td>$r[idx]</td>
		            <td><a href=?module=nilai&act=editnilai&nis=$r[nis]>Edit</a> | 
		                <a href='$aksi?module=nilai&act=hapus&nis=$r[nis]' onClick=\"return confirm('Anda yakin akan menghapus $r[nama]?')\">Hapus</a></td>
		        </tr>";
      $no++;
    }
    echo "</table>";

    $jmldata = mysql_num_rows(mysql_query("SELECT * FROM nilai"));
      
    $jmlhalaman  = $p->jumlahHalaman($jmldata, $batas);
    $linkHalaman = $p->navHalaman($_GET[halaman], $jmlhalaman);

    echo "<div id=paging>$linkHalaman</div><br>";
 
    break;    
    }
    else{
    echo "<table width='700'>  
          <tr id='ijo'><th>No</th><th>NIS</th> <th>Nama</th><th>Kelas</th>  <th>Mata Pelajaran</th> <th>Ulangan</th><th>UTS</th><th>UAS</th><th>NA</th><th>Indeks</th><th></th></tr>";

    $p      = new Paging9;
    $batas  = 15;
    $posisi = $p->cariPosisi($batas);

	$tampil = mysql_query("SELECT k.kelas, n.*, s.nama, m.nama_matpel from nilai n, siswa s, kelas k, matpel m WHERE n.nis=s.nis AND n.kd_matpel=m.kd_matpel AND n.kd_kelas=k.kd_kelas  AND n.nis LIKE '%$_GET[nis]%' ORDER BY kd_kelas ASC LIMIT $posisi,$batas");
	
      
    $no = $posisi+1;
    while($r=mysql_fetch_array($tampil)){
      echo "<tr><td>$no</td>
                <td>$r[nis]</td>                
                <td>$r[nama]</td>                
                <td>$r[kelas]</td>
                <td>$r[nama_matpel]</td>
                <td>$r[ul]</td>
                <td>$r[uts]</td>
                <td>$r[uas]</td>
                <td>$r[nilai_akhir]</td>
                <td>$r[idx]</td>
		            <td><a href=?module=nilai&act=editnilai&nis=$r[nis]>Edit</a> | 
		                <a href='$aksi?module=nilai&act=hapus&nis=$r[nis]'>Hapus</a></td>
		        </tr>";
      $no++;
    }
    echo "</table>";

    $jmldata = mysql_num_rows(mysql_query("SELECT * FROM nilai WHERE nis LIKE '%$_GET[nis]%'"));
    
    $jmlhalaman  = $p->jumlahHalaman($jmldata, $batas);
    $linkHalaman = $p->navHalaman($_GET[halaman], $jmlhalaman);

    echo "<div id=paging>$linkHalaman</div><br>";
 
    break;    
    }
					break;
				case "tambahnilai":
					?>
					<form method="post" name="add" id="add" action="<?php echo $_SERVER['PHP_SELF']; ?>?module=nilai&act=input">
                        
						<table class='putih' border="0" width="650">
						<tr>
						<td colspan="4">
						<ul class="templatemo_list">
						<li><strong>TAMBAH DATA NILAI SISWA</strong></li>
						</ul>
						</td>
						</tr>
						
						<tr>
						<td>Guru </td> <td colspan="3">
						<?php
						echo "
						<select name='nip'>"; 
							  $tampil=mysql_query("SELECT * FROM guru order by nip");
							  while($w=mysql_fetch_array($tampil)){
								echo "<option value=$w[nip]>$w[nip] - $w[nama]</option>";								
							  }
						echo "</select>";
						?>
						</td>  
						</tr>
						
						<tr>
						<td>Mata Pelajaran </td> <td colspan="3">
						<?php
						echo "
						<select name='kd_matpel'>"; 
							  $tampil=mysql_query("SELECT * FROM matpel order by kd_matpel");
							  while($w=mysql_fetch_array($tampil)){
								echo "<option value=$w[kd_matpel]>$w[nama_matpel]</option>";								
							  }
						echo "</select>";
						?>
						</td>  
						</tr>
						
						<tr>
						<td>Siswa </td> <td colspan="3">
						<?php
						echo "
						<select name='nis'>"; 
							  $tampil=mysql_query("SELECT * FROM siswa order by nis");
							  while($w=mysql_fetch_array($tampil)){
								echo "<option value=$w[nis]>$w[nis] - $w[nama]</option>";								
							  }

						echo "</select>";
						?>
						</td>  
						</tr>
						<tr>
						<td>Kelas </td> <td colspan="3">
						<?php
						echo "
						<select name='kd_kelas'>"; 
							  $tampil=mysql_query("SELECT * FROM kelas");
							  while($w=mysql_fetch_array($tampil)){
								echo "<option value=$w[kd_kelas]>$w[kelas]</option>";								
							  }

						echo "</select>";
						?>
						</td>  
						</tr>
						
						<tr>
						<td>Nilai Ulangan</td> <td colspan="3"> <input type="text" name="ul" onkeyup="hitungAdd()" size="5" /> </td>
						</tr>						
						
						<tr>
						<td>Nilai UTS</td> <td colspan="3"> <input type="text" name="uts" onkeyup="hitungAdd()"size="5" /> </td>
						</tr>
						
						<tr>
						<td>Nilai UAS</td> <td colspan="3"> <input type="text" name="uas" onkeyup="hitungAdd()" size="5" /> </td>
						</tr>
						
						<tr>
						<td>Nilai Akhir</td> <td colspan="3"> <input type="text" readonly name="nilai_akhir" size="5" /> </td>
						</tr>
						
						<tr>
						<td>Indeks</td> <td colspan="3"> <input type="text" name="idx" readonly size="5" /> </td>
						</tr>
						
						<tr>
						<td>						
						</td>
						<td colspan="3">				
                        <input type="submit" value="Simpan" id="submit" name="submit" class="submit_btn float_l" />
						&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        <input type="reset" value="Reset" id="reset" name="reset" class="submit_btn float_l" />
						</td>						
						</tr>
						</table>					
                    </form>
					<?php
					break;
					
				case "editnilai":
				$edit = mysql_query("SELECT * FROM nilai WHERE nis='$_GET[nis]' ");
				$r    = mysql_fetch_array($edit);
					?>
					<form method="post" name="edit" id='edit' action="<?php echo $_SERVER['PHP_SELF']; ?>?module=nilai&act=edit">
                        
						<table class='putih' border="0" width="650">
						<tr>
						<td colspan="4">
						<ul class="templatemo_list">
						<li><strong>DATA NILAI SISWA</strong></li>
						</ul>
						</td>
						</tr>
						
						<tr>
						<td>Siswa</td> <td colspan="3">
						<?php
						echo "
						<select name='nis'>"; 
							  $tampil=mysql_query("SELECT * FROM siswa");
							  while($w=mysql_fetch_array($tampil)){
								if ($r[nis]==$w[nis]){
								  echo "<option value=$w[nis] selected>$w[nis] - $w[nama]</option>";
								}
								else{
								  //echo "<option value=$w[nis]>$w[nis] - $w[nama]</option>";
								}
							  }

						echo "</select>";
						?>
						</td>                        
						</tr>
						
						<tr>
						<td>Kelas</td> <td colspan="3">
						<?php
						echo "
						<select name='kd_kelas'>"; 
							  $tampil=mysql_query("SELECT * FROM kelas");
							  while($w=mysql_fetch_array($tampil)){
								if ($r[kd_kelas]==$w[kd_kelas]){
								  echo "<option value=$w[kd_kelas] selected>$w[kelas]</option>";
								}
								else{
								  //echo "<option value=$w[kd_kelas]>$w[kelas]</option>";
								}
							  }

						echo "</select>";
						?>
						</td>                        
						</tr>
						
						<tr>
						<td>Guru</td> <td colspan="3">
						<?php
						echo "
						<select name='nip'>"; 
							  $tampil=mysql_query("SELECT * FROM guru");
							  while($w=mysql_fetch_array($tampil)){
								if ($r[nip]==$w[nip]){
								  echo "<option value=$w[nip] selected>$w[nama]</option>";
								}
								else{
								  //echo "<option value=$w[nip]>$w[nama]</option>";
								}
							  }

						echo "</select>";
						?>
						</td>                        
						</tr>
						
						<tr>
						<td>Mata Pelajaran</td> <td colspan="3">
						<?php
						echo "
						<select name='kd_matpel'>"; 
							  $tampil=mysql_query("SELECT * FROM matpel");
							  while($w=mysql_fetch_array($tampil)){
								if ($r[kd_matpel]==$w[kd_matpel]){
								  echo "<option value=$w[kd_matpel] selected>$w[nama_matpel]</option>";
								}
								else{
								  //echo "<option value=$w[kd_matpel]>$w[nama_matpel]</option>";
								}
							  }

						echo "</select>";
						?>
						</td>                        
						</tr>
												
						<tr>
						<td>Nilai Ulangan</td> <td colspan="3"> <input type="text" name="ul" onkeyup="hitungEdit()" size="5" value="<?php echo $r[ul]; ?>"/> </td>
						</tr>						
						
						<tr>
						<td>Nilai UTS</td> <td colspan="3"> <input type="text" name="uts" onkeyup="hitungEdit()"size="5" value="<?php echo $r[uts]; ?>" /> </td>
						</tr>
						
						<tr>
						<td>Nilai UAS</td> <td colspan="3"> <input type="text" name="uas" onkeyup="hitungEdit()" size="5" value="<?php echo $r[uas]; ?>" /> </td>
						</tr>
						
						<tr>
						<td>Nilai Akhir</td> <td colspan="3"> <input type="text" readonly name="nilai_akhir" size="5" value="<?php echo $r[nilai_akhir]; ?>" /> </td>
						</tr>
						
						<tr>
						<td>Indeks</td> <td colspan="3"> <input type="text" name="idx" readonly size="5" value="<?php echo $r[idx]; ?>"/> </td>
						</tr>
						
						
						<tr>
						<td>						
						</td>
						<td colspan="3">				
                        <input type="submit" value="Simpan" id="submit" name="submit" class="submit_btn float_l" />
						&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        <input type="reset" value="Reset" id="reset" name="reset" class="submit_btn float_l" />
						</td>						
						</tr>
						</table>
                    </form>
					<?php
					break;
					
				
				}
				?>				
        		</div>
                </div>
                
            	<div class="cleaner"></div>   
            </div>        
        </div>
    
    </div> <!-- end of templatemo_wrapper -->
</div> <!-- end of templatemo_outer_wrapper -->

<?php
	include "../footer.php";
?>

</body>
</html>
